import { ref } from 'vue'
const time = ref('')
const nowDate = ref('')

export function useRealTime() {
  const date = new Date()
  const h = date.getHours() >= 10 ? date.getHours() : `0${date.getHours()}`
  const m = date.getMinutes() >= 10 ? date.getMinutes() : `0${date.getMinutes()}`
  let s = date.getSeconds()

  time.value = `${h}:${m}`
  nowDate.value = date.toLocaleDateString()
  let timer: any
  timer = setInterval(() => {
    if (s >= 60) {
      clearInterval(timer)
      useRealTime()
    } else {
      s++
    }
  }, 1000)

  return [time, nowDate]
}
